package com.cbank.dao;

import com.cbank.domain.BaseEntity;
import com.cbank.domain.ModuleShowDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ModuleShowDetailDao {
    public static final String ALL="id,view_id,create_time,update_time,module_show_id,url,cn_title,en_title,cn_sub_title,en_sub_title,cn_article,en_article,type,link_url,banner_url,article_time,cn_label,en_label,en_article_time";

    @Select("select "+ALL+" from module_show_detail where id = #{id}")
    ModuleShowDetail getById(Integer id);

    @Select("select "+ALL+" from module_show_detail where view_id = #{view_id}")
    ModuleShowDetail getByviewId(String viewId);

    @Select("select "+ALL+" from module_show_detail where module_show_id = #{moduleShowId} and type = #{type} and status = "+ BaseEntity.STATUS_VALID)
    List<ModuleShowDetail> getListByModuleShowIdAndType(@Param(value = "moduleShowId")Integer moduleShowId,@Param(value = "type")Integer type);

    @Select("select "+ALL+" from module_show_detail where module_show_id = #{moduleShowId}  and status = "+ BaseEntity.STATUS_VALID)
    List<ModuleShowDetail> getAllListByModuleShowId(@Param(value = "moduleShowId")Integer moduleShowId);

    @Insert("insert into module_show_detail (view_id,module_show_id,url,cn_title,en_title,cn_sub_title,en_sub_title,cn_article,en_article,type,link_url,banner_url,article_time,cn_label,en_label,en_article_time) " +
            "values (#{viewId},#{moduleShowId},#{url},#{cnTitle},#{enTitle},#{cnSubTitle},#{enSubTitle},#{cnArticle},#{enArticle},#{type},#{linkUrl},#{bannerUrl},#{articleTime},#{cnLabel},#{enLabel},#{enArticleTime})")
    void insert(ModuleShowDetail moduleShowDetail);

    @Update("update module_show_detail set view_id=#{viewId},module_show_id=#{moduleShowId},url=#{url},cn_title=#{cnTitle},en_title=#{enTitle},cn_sub_title=#{cnSubTitle},en_sub_title=#{enSubTitle}," +
            "cn_article=#{cnArticle},en_article=#{enArticle},type=#{type},link_url=#{linkUrl},banner_url=#{bannerUrl},article_time=#{articleTime},cn_label=#{cnLabel},en_label=#{enLabel},en_article_time=#{enArticleTime} where id = #{id}")
    void update(ModuleShowDetail moduleShowDetail);

    @Update("update module_show_detail set status = #{status} where id = #{id}")
    void updateStatus(@Param(value = "status")Integer status,@Param(value = "id")Integer id);

    @Update("update module_show_detail set module_show_id = #{moduleShowId} where id = #{id}")
    void updateModuleShowId(@Param(value = "moduleShowId")Integer moduleShowId,@Param(value = "id")Integer id);
}
